<?php /* УТФ-8:fix */

class SPImodel__profiles__front extends SPImodel__profiles
{
    public function select( $type )
    {
        switch( $type )
        {
            case 'dj':          $permission_id = SPI_IAM_PERM_DJ; break;
            case 'journalist':  $permission_id = SPI_IAM_PERM_JOURNALIST; break;
            default:            $permission_id = 0; break;
        }
        $query =    " SELECT *, fname||' '||lname as name "
               .      " FROM ".SPIcfg::$store['table:profiles']
               .     " WHERE workstatus=1 "
               . $this->qfield_permission( 'permissions', $permission_id )
               . " ORDER BY name ASC, id DESC "
               ;

        return SPIstore::I()->query( $query );
    }

    public function get_by_id( $item_id )
    {
        $query =    " SELECT * "
               .      " FROM ".SPIcfg::$store['table:profiles']
               .     " WHERE id=" . (int) $item_id
               .       " AND workstatus=1 "
               ;

        return SPIstore::I()->query( $query )->fetch_and_close();
    }
}
